<?php
$sqliteDb='sqlite:speedCheck.sqlite';
if (!$db = new PDO($sqliteDb) )
die("Error open DB");


// Create Table
try {
$result = $db->exec("CREATE TABLE FACTS (name TEXT, provider TEXT, latitude TEXT, longitude TEXT, speed TEXT, timestamp TEXT)");
} catch (PDOException $e) {
   print "Error Create!: " . $e->getMessage() . "<br/>";
   die();
}

// Insert new fact
if (!empty($_POST['latitude']) && !empty($_POST['longitude']) && !empty($_POST['speed']))
{
	$name = $_POST['name'];
	$provider = $_POST['provider'];
	$latitude = $_POST['latitude'];
	$longitude = $_POST['longitude'];
	$speed = $_POST['speed'];
	$timestamp = $_POST['timestamp'];
	

	$query = "INSERT  INTO FACTS (name, provider, latitude, longitude, speed, timestamp) VALUES ('${name}', '${provider}', '${latitude}', '${longitude}', '${speed}', '${timestamp}')";
	try {
		$result = $db->exec($query);
	} catch (PDOException $e) {
		print "Error Insert!: " . $e->getMessage() . "<br/>";
		die();
	}
}
?>

<!DOCTYPE html>
<html>
<head>
  <title>SpeedTest</title>
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
  <link rel="icon" type="image/png" href="iui/iui-favicon.png">
  <link rel="apple-touch-icon" href="iui/iui-logo-touch-icon.png" />
  <link rel="stylesheet" href="iui/iui.css" type="text/css" />
  <link rel="stylesheet" title="Default" href="iui/t/default/default-theme.css"  type="text/css"/>
  <link rel="stylesheet" href="css/iui-panel-list.css" type="text/css" />
  <style type="text/css">
.panel p.normalText { text-align: left;  padding: 0 10px 0 10px; }
  </style>
  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-8634743-10'], ['_trackPageview']);
  </script>
  <script type="text/javascript">
    (function() {
        var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
        ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
        var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>
  <script type="text/javascript" src="tinytst1.js?v8"></script>
</head>

<?php
/*
if (!empty($_POST['name']) && !empty($_POST['provider']))
{
	$name = $_POST['name'];
	$provider = $_POST['provider'];
	
	echo ('<body onLoad="setcookie('.$name.','.$provider.');">');
}
else
{
	echo('<body>');
}
*/
?>

<body>
    <div class="toolbar">
        <h1 id="pageTitle">SpeedTest</h1>
        <a id="backButton" class="button" href="#"></a>
    </div>

<div id="home" class="panel" selected="true">
  <h2>Neue Messungen</h2>
  <ul>
	<li><a href="result.php?platform=0">GPRS</a></li>
	<li><a href="result.php?platform=1">EDGE</a></li>
	<li><a href="result.php?platform=2">3G</a></li>
	<li><a href="result.php?platform=3">WIFI</a></li>
  </ul>  
  <h2>Sonstiges</h2>
  <ul>
	<li><a id="gobut" href="results.php">Messungen</a></li>
  </ul>  
  
</div>



</body>
</html>
